package threadTestDemo;

import java.util.concurrent.*;

public class MyThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建了线程池对象
        //线程池的submit方法替代了thread的构造方法和start方法，
        //线程池可以一直提交任务，处理请求，

        MyRunnable myRunnable1=new MyRunnable(10);
        MyRunnable myRunnable2=new MyRunnable(20);
        MyRunnable myRunnable3=new MyRunnable(30);
        ExecutorService executorService= Executors.newFixedThreadPool(2);
        Future<String> submitResultFuture = (Future<String>) executorService.submit(myRunnable1);
        System.out.println(submitResultFuture.get());
        executorService.submit(myRunnable2);
        executorService.submit(myRunnable3);
        executorService.shutdown();
    }
}
